package com.zbkj.crmeb.merchant.admin.controller;


import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.member.service.IChannelMerchantAttributeService;
import com.zbkj.crmeb.store.model.StoreProductPicking;
import com.zbkj.crmeb.store.request.BatchUpdatePriceRequest;
import com.zbkj.crmeb.store.request.PickingProductRequest;
import com.zbkj.crmeb.store.request.UpdatePickingPriceRequest;
import com.zbkj.crmeb.store.service.StoreProductPickingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 批采商品表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-05-19
 */
@RestController
@RequestMapping("/api/admin/mer/picking/product")
@Api(tags = "商户后台-批采单商品")
public class MerStoreProductPickingController extends AdminBaseController {

    @Autowired
    private StoreProductPickingService storeProductPickingService;
    @Autowired
    private IChannelMerchantAttributeService channelMerchantAttributeService;

    @ApiOperation("批量修改价格")
    @PutMapping("/batch/update/price")
    public CommonResult<Object> batchUpdatePrice(@RequestBody @Validated UpdatePickingPriceRequest request) {
        return storeProductPickingService.batchUpdatePrice(request);
    }

    @ApiOperation("编辑批采商品")
    @PutMapping("/update")
    public CommonResult<Object> updatePickingProduct(@RequestBody @Validated PickingProductRequest request) {
        return storeProductPickingService.updatePickingProduct(request);
    }

    @ApiOperation("批量移除")
    @DeleteMapping("/batch/delete")
    public CommonResult<Object> batchDelete(@RequestParam(value = "ids") List<Integer> ids) {
        return storeProductPickingService.batchDelete(ids);
    }

    @ApiOperation("批量加入批采单")
    @PostMapping("/batch/add")
    public CommonResult<Object> batchAddPicking(@RequestParam(value = "ids") List<Integer> ids,
                                                @RequestParam(value = "pickingId") Integer pickingId) {
        return storeProductPickingService.batchAddPicking(ids,pickingId);
    }

    @ApiOperation(value = "获取导航栏批采单是否开启")
    @RequestMapping(value = "/picking/getAppBarInfo", method = RequestMethod.GET)
    public CommonResult<Integer> getAppBarInfo(HttpServletRequest request){
        Integer merId = getMerId(request);
        return CommonResult.success(channelMerchantAttributeService.getAppBarInfo(merId));
    }

    @ApiOperation(value = "修改批采单导航栏是否开启")
    @PutMapping(value = "/picking/updateAppBarStatus")
    public CommonResult<Boolean> updateAppBarStatus(HttpServletRequest request,@RequestParam(value = "status") Integer status){
        Integer merId = getMerId(request);
        return CommonResult.success(channelMerchantAttributeService.updatePickingAppBar(merId,status));
    }

}

